﻿using System;
using System.Net;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;

namespace Components.Analytics
{
    [DataContract]
    public class DocumentClusteringInstruction : InstructionBase
    {
        #region props
        [DataMember]
        public string TaskName { get; set; }

        [DataMember]
        public string ConnStr { get; set; }
        [DataMember]
        public string SQL { get; set; }
        [DataMember]
        public string DocIDFieldFromSQL { get; set; }
        [DataMember]
        public string DocTitleFieldFromSQL { get; set; }

        [DataMember]
        public string TermDB { get; set; }
        [DataMember]
        public string TermTable { get; set; }
        [DataMember]
        public string MappingTable { get; set; }

        [DataMember]
        public string TermIDFieldInTermTable { get; set; }
        [DataMember]
        public string PhraseFieldInTermTable { get; set; }
        [DataMember]
        public string TermIDFieldInMappingTable { get; set; }
        [DataMember]
        public string DocIDFieldInMappingTable { get; set; }
        [DataMember]
        public string TermFreqFieldInMappingTable { get; set; }

        [DataMember]
        public string OutputDB { get; set; }
        [DataMember]
        public string ResultTable { get; set; }
        [DataMember]
        public string TaskNameField { get; set; }
        [DataMember]
        public string DataField { get; set; }
        #endregion

        #region ctor
        public DocumentClusteringInstruction()
            : base(Guid.Empty, Guid.Empty)
        {
            this.TaskName = string.Empty;
            this.ConnStr = string.Empty;
            this.SQL = string.Empty;
            this.DocIDFieldFromSQL = string.Empty;
            this.DocTitleFieldFromSQL = string.Empty;

            this.TermDB = string.Empty;
            this.TermTable = string.Empty;
            this.MappingTable = string.Empty;

            this.TermIDFieldInTermTable = string.Empty;
            this.TermIDFieldInMappingTable = string.Empty;
            this.PhraseFieldInTermTable = string.Empty;
            this.DocIDFieldInMappingTable = string.Empty;
            this.TermFreqFieldInMappingTable = string.Empty;

            this.OutputDB = string.Empty;
            this.ResultTable = string.Empty;
            this.TaskNameField = string.Empty;
            this.DataField = string.Empty;
        }

        public DocumentClusteringInstruction(Guid componentID, Guid ticketID,
            string taskName, string connStr, string sql,
            string docIDFromSrc, string docTitleFieldFromSQL,
            string termDB, string termTable, string mappingTable,
            string termIDFieldInTermTable, string phraseFieldInTermTable,
            string termIDFieldInMappingTable,
            string docIDFieldInMappingTable,
            string termFreqFieldInMappingTable,
            string outputDB, string resultTable,
            string taskField, string resultDataField)
            : base(componentID, ticketID)
        {
            this.TaskName = taskName;
            this.ConnStr = connStr;
            this.SQL = sql;
            this.DocIDFieldFromSQL = docIDFromSrc;
            this.DocTitleFieldFromSQL = docTitleFieldFromSQL;

            this.TermDB = termDB;
            this.TermTable = termTable;
            this.MappingTable = mappingTable;

            this.TermIDFieldInTermTable = termIDFieldInTermTable;
            this.PhraseFieldInTermTable = phraseFieldInTermTable;
            this.TermIDFieldInMappingTable = termIDFieldInMappingTable;
            this.DocIDFieldInMappingTable = docIDFieldInMappingTable;
            this.TermFreqFieldInMappingTable = termFreqFieldInMappingTable;

            this.OutputDB = outputDB;
            this.ResultTable = resultTable;
            this.TaskNameField = taskField;
            this.DataField = resultDataField;
        }
        #endregion

        #region Overrides of InstructionBase

        public override XElement Serialize()
        {
            XElement xe = base.Serialize();
            xe.Add(new XAttribute("TaskName", this.TaskName));
            xe.Add(new XAttribute("ConnStr", this.ConnStr));
            xe.Add(new XAttribute("SQL", this.SQL));
            xe.Add(new XAttribute("DocIDFieldFromSQL", this.DocIDFieldFromSQL));
            xe.Add(new XAttribute("DocTitleFieldFromSQL", this.DocTitleFieldFromSQL));

            xe.Add(new XAttribute("TermDB", this.TermDB));
            xe.Add(new XAttribute("TermTable", this.TermTable));
            xe.Add(new XAttribute("MappingTable", this.MappingTable));

            xe.Add(new XAttribute("TermIDFieldInTermTable", this.TermIDFieldInTermTable));
            xe.Add(new XAttribute("PhraseFieldInTermTable", this.PhraseFieldInTermTable));
            xe.Add(new XAttribute("TermIDFieldInMappingTable", this.TermIDFieldInMappingTable));
            xe.Add(new XAttribute("DocIDFieldInMappingTable", this.DocIDFieldInMappingTable));
            xe.Add(new XAttribute("TermFreqFieldInMappingTable", this.TermFreqFieldInMappingTable));

            xe.Add(new XAttribute("OutputDB", this.OutputDB));
            xe.Add(new XAttribute("ResultTable", this.ResultTable));
            xe.Add(new XAttribute("TaskNameField", this.TaskNameField));
            xe.Add(new XAttribute("DataField", this.DataField));
            return xe;
        }

        public override InstructionBase Instantiate(XElement xe)
        {
            DocumentClusteringInstruction instruction = (DocumentClusteringInstruction)base.Instantiate(xe);
            instruction.TaskName = xe.Attribute("TaskName").Value;
            instruction.ConnStr = xe.Attribute("ConnStr").Value;
            instruction.SQL = xe.Attribute("SQL").Value;
            instruction.DocIDFieldFromSQL = xe.Attribute("DocIDFieldFromSQL").Value;
            instruction.DocTitleFieldFromSQL = xe.Attribute("DocTitleFieldFromSQL").Value;

            instruction.TermDB = xe.Attribute("TermDB").Value;
            instruction.TermTable = xe.Attribute("TermTable").Value;
            instruction.MappingTable = xe.Attribute("MappingTable").Value;

            instruction.TermIDFieldInTermTable = xe.Attribute("TermIDFieldInTermTable").Value;
            instruction.PhraseFieldInTermTable = xe.Attribute("PhraseFieldInTermTable").Value;
            instruction.TermIDFieldInMappingTable = xe.Attribute("TermIDFieldInMappingTable").Value;
            instruction.DocIDFieldInMappingTable = xe.Attribute("DocIDFieldInMappingTable").Value;
            instruction.TermFreqFieldInMappingTable = xe.Attribute("TermFreqFieldInMappingTable").Value;

            instruction.OutputDB = xe.Attribute("OutputDB").Value;
            instruction.ResultTable = xe.Attribute("ResultTable").Value;
            instruction.TaskNameField = xe.Attribute("TaskNameField").Value;
            instruction.DataField = xe.Attribute("DataField").Value;
            return instruction;
        }

        #endregion
    }
}
